/*
作者：江怀玉
日期：2014-06-10
功能：弹出菜单
解决：
-------------------------------------
依赖JS:
jquery,jquery.data
依赖CSS：

---------------------------------------------------------*/
//初始化控件
(function ($) {
    $.fnCalender = function (ctrl, year, option) {
        if (ctrl == undefined) {
            return;
        }
        var _option = option ? {} : option;
        for (var i = 1; i < 13; i++) {
            $("#" + ctrl).append("<div class=\"calender\" id=\"div_calender_" + i + "\"></div>");
            carHtml(year, i);
        }

        function carHtml(vYear, vMonth, vDay, vipt) {
            var vDate = vYear + "-" + vMonth + "-1";
            //if(vMonth<10) vMonth="0"+vMonth;
            var vWeek = getWeek(vDate);
            var vDayNum = getDayNum(vYear, vMonth);
            var tmpNum = Number(vDayNum) - 7 + Number(vWeek);
            if ((tmpNum % 7) == 0) var line = tmpNum / 7;
            else var line = parseInt(tmpNum / 7) + 1;
            var carArr = new Array();
            carArr.push("<table border='0' cellspacing='0' cellpadding='0'>");
            carArr.push("<tr><td colspan='7'><table border='0' cellspacing='0' cellpadding='0'>");
            carArr.push("<tr><td width='13'>&nbsp;</td><td width='20'><span id='ylow' bj='cBj'>&lt;&lt;</span></td><td width='44'>");
            carArr.push(vYear + "</td>");
            carArr.push("<td width='20'>年</td><td width='25' height='30'>");
            carArr.push(vMonth + "</td>");
            carArr.push("<td width='20'>月</td><td width='20'><span id='yadd' bj='cBj'>&gt;&gt;</span></td><td width='13'>&nbsp;</td>");
            carArr.push("</tr></table></td></tr>");
            carArr.push("<tr id='cssWeek'><td>日</td><td>一</td>");
            carArr.push("<td>二</td><td>三</td>");
            carArr.push("<td>四</td><td>五</td>");
            carArr.push("<td>六</td></tr>");
            for (var i = 0; i <= line; i++) {
                carArr.push("<tr>");
                for (var j = 0; j < 7; j++) {
                    var tDay = Number(i * 7) + Number(j) - Number(vWeek) + 1;
                    if (tDay < 1 || tDay > vDayNum) carArr.push("<td>&nbsp;</td>");
                    else if (tDay == vDay) carArr.push("<td><a href='#this' id='cur' ipt='" + vipt + "'>" + tDay + "</a></td>");
                    else carArr.push("<td><a href='#this' ipt='" + vipt + "'>" + tDay + "</a></td>");
                }
                carArr.push("</tr>");
            }
            carArr.push("</table>")
            var htmlStr = carArr.join("");
            $("#div_calender_" + vMonth).html(htmlStr);
        }
    }
})(jQuery);



